package main

import (
	"bytes"
	"fmt"

	"gitee.com/mayarn/crawler/collect"
	"github.com/PuerkitoBio/goquery"
)

// tag v0.0.9
func main() {
	url := "https://www.thepaper.cn/"
	var f collect.Fetcher = collect.BaseFetch{}
	body, err := f.Get(url)

	if err != nil {
		fmt.Printf("read content failed:%v", err)
		return
	}

	// 加载HTML文档
	doc, err := goquery.NewDocumentFromReader(bytes.NewReader(body))
	if err != nil {
		fmt.Printf("read content failed:%v", err)
	}

	//doc.Find("div.news_li h2 a[target=_blank]")
	doc.Find("div.small_cardcontent__BTALp h2").Each(func(i int, s *goquery.Selection) {
		// 获取匹配标签中的文本
		title := s.Text()
		fmt.Printf("Review %d: %s\n", i, title)
	})
}
